﻿using Peak.Core;
using Peak.Resources;

namespace Peak.Web.Controllers.Models
{
  public class SearchResultItem
  {
    public string Name { get; set; }
    public SearchResultItemType Type { get; set; }       
    public int Id { get; set; }
    public User Assigned { get; set; }
    public string Path { get; set; }
    public string Status { get; set; }

    public SearchResultItem(Task task)
    {
      Id = task.Id;
      Type = SearchResultItemType.Task;
      Name = task.Name;
      Assigned = task.AssignedTo;
      if(task.Story != null)
      {
        if(task.Story.Sprint != null)
        {
          Path = task.Story.Sprint.Name + " \\ " + task.Story.Name;
        }
        else
        {
          Path = Labels.Backlog + " \\ " + task.Story.Name;
        }
      }
      Status = Statuses.ResourceManager.GetString(task.Status.ToString());
    }

    public SearchResultItem(Story story)
    {
      Id = story.Id;
      Type = SearchResultItemType.Story;
      Name = story.Name;
      if (story.Sprint != null)
      {
        Path = story.Sprint.Name;
      }
      else
      {
        Path = Labels.Backlog;
      }
      Status = Statuses.ResourceManager.GetString(story.Status.ToString());
    }
  }
}
